/**
 * web2010_admin
 * com.xsoft.web.interceptor AdminInterceptor.java
 */
package com.xsoft.web.interceptor;

import java.util.ArrayList;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author 潘冬 2010-8-19 下午05:02:36
 */
public class AdminInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		
		System.out.println("Action Class:"+ arg0.getAction().getClass().getSimpleName());
		System.out.println("Invocation Context:"+ arg0.getInvocationContext().getName());
		
		HttpServletResponse response = (HttpServletResponse)arg0.getInvocationContext().get(ServletActionContext.HTTP_RESPONSE);
		
		Map session = arg0.getInvocationContext().getSession();
		if (session.get("user") == null) {
			session.clear();
			response.sendRedirect("http://localhost:8086/fuli/manager/login.jsp");
			return null;
//			return "login"; //这里尽量不要这样些，因为他是服务器内部的调整。url并不改变的。
		}
		
		
		return arg0.invoke();
	}

}
